var app = getApp()
var utils = require('../../utils/utils.js')
Page({
    data: {
        soleOVerIcon:utils.sysConst.soleOVerIcon,
        defaultSize: 'default',
        primarySize: 'default',
        warnSize: 'default',
        disabled: false,
        plain: false,
        loading: false
    },
    onLoad: function(options) {
        var that = this
        var param={"id":options.id}
        wx.request({
            url: utils.sysConst.productDetailPath,
            method: 'GET',
            data: param,
            header: {
                'Accept': 'application/json','appVersion':utils.appVersion,'signValue':utils.getSignValue(param)
            },
            success: function(res) {
                if (res.data.code == 1){
                    that.setData({
                        productInfo: res.data.data,
                        soleOVerIcon:utils.sysConst.soleOVerIcon,
                    });
                }

            }
        })
    },
    //加入购物车-start
    addCart:function(event){
        //console.log("app.globalData.openid-addCart",app.globalData.openid)
        //设置提交按钮不可用
        this.setData({
            disabled: !this.data.disabled,
            loading: !this.data.loading
        })
        wx.showLoading({
            title: '处理中...',
        })
        var param = {"productId":event.detail.value.productId,"openId":app.globalData.openid}
        wx.request({
            url: utils.sysConst.addCartPath,
            method: 'POST',
            header: {
                "Content-Type": "application/x-www-form-urlencoded",'appVersion':utils.appVersion,'signValue':utils.getSignValue(param)
            },
            data: param,
            dataType: "json",
            success: function(res) {
                wx.hideLoading();
                if (res.data.code == 1){
                    wx.showToast({
                        title: '添加成功',
                        icon: 'success',
                        duration: 2000
                    })
                }else{
                    wx.showToast({
                        title:res.data.msg,
                        icon: 'none',
                        duration: 2000
                    })
                }
            }
        })
        // 设置提交按钮可用
        this.setData({
            disabled: !this.data.disabled,
            loading: !this.data.loading
        })
        //
    },
    //加入购物车-end
})
